using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace CodePlex.DnD4eCampaignManager.DnD4e
{
    public static class ListExtensions
    {
        public static bool Equivalent(this IList list, IList secondList)
        {
            if ( list == null && secondList == null )
            {
                return true;
            }
            if ( ( list != null && secondList == null ) || ( list == null ) )
            {
                return false;
            }
            if ( list.Count != secondList.Count )
            {
                return false;
            }
            foreach ( object item in list )
            {
                if ( !secondList.Contains(item) )
                {
                    return false;
                }
            }
            return true;
        }

        public static string ToCommaDelimitedString(this List<string> list)
        {
            StringBuilder builder = new StringBuilder();
            foreach ( string item in list )
            {
                builder.AppendFormat("{0}, ", item);
            }
            return builder.ToString(0, builder.Length - 2);
        }

        public static List<string> ToListOfStrings(this string list)
        {
            List<string> listOfStrings = new List<string>();
            foreach ( string item in list.Trim().Split(',') )
            {
                listOfStrings.Add(Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(item.Trim()));
            }
            return listOfStrings;
        }
    }
}